package com.iwomy.secureplat.platform.service.impl;

import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.iwomy.secureplat.common.core.constant.CacheConstants;
import com.iwomy.secureplat.platform.entity.BasicSensorUnitEntity;
import com.iwomy.secureplat.platform.mapper.BasicSensorUnitMapper;
import com.iwomy.secureplat.platform.service.BasicSensorUnitService;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

/**
 * 传感器单位
 *
 * @author pig
 * @date 2024-01-04 18:52:01
 */
@Service
public class BasicSensorUnitServiceImpl extends ServiceImpl<BasicSensorUnitMapper, BasicSensorUnitEntity> implements BasicSensorUnitService {
	@Override
	@Cacheable(value = CacheConstants.SENSOR_UNIT + "#10", key = "#unitCode")
//	@CacheEvict(value = CacheConstants.SENSOR_UNIT, key = "#unitCode")
	public BasicSensorUnitEntity oneByUnitCode(String unitCode) {
		BasicSensorUnitEntity one = this.getOne(Wrappers.lambdaQuery(BasicSensorUnitEntity.class)
				.eq(BasicSensorUnitEntity::getSensorUnitCode, unitCode));
		if (ObjectUtil.isNotNull(one)) return one;
		one = new BasicSensorUnitEntity();
		one.setSensorUnitCode(unitCode);
		one.setSensorUnitName(unitCode);
		return one;
	}
}